package com.dts.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dts.advice.R;
import com.dts.dto.EmpQueryDto;
import com.dts.entity.Emp;
import com.dts.service.EmpService;
import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/emp")
public class EmpController {

    private static Logger logger = LoggerFactory.getLogger(EmpController.class);

    @Autowired
    private EmpService empService;

    @RequestMapping("/single")
    public Emp single(Integer  empId){
        return empService.selectEmpById(empId);
    }

    @RequestMapping("/list")
    public Page<Emp> list(@RequestBody EmpQueryDto dto){
        Page<Emp> empPage = empService.selectEmpPage(new Page<>(dto.getPageNum(), dto.getPageSize()), dto);
        return empPage;
    }

    @RequestMapping("/add")
    public R add(@RequestBody Emp emp){
        empService.insertEmp(emp);
        return R.ok();
    }

    @RequestMapping("/update")
    public R update(@RequestBody Emp emp){
        empService.updateEmp(emp);
        return R.ok();
    }

    @RequestMapping("/delete")
    public R delete(int empId){
        empService.deleteEmp(empId);
        return R.ok();
    }

    @PostConstruct
    public void init(){
        System.out.println("EmpController init");
    }

}
